package com.fc.tms.dao;

import org.springframework.stereotype.Repository;

import com.fc.framework.dao.HibernateBaseDAO;
import com.fc.tms.entity.User;

@Repository("userDAO")
public class UserDAO extends HibernateBaseDAO<User, Long> {

    public boolean isExist(String eName) {
        String hqlString = "SELECT u.id From User u WHERE u.eName = :eName";
        return this.createQuery(hqlString).setParameter("eName", eName).setMaxResults(1).uniqueResult() != null;
    }

    public User getByeName(String eName) {
        String hqlString = "From User u WHERE u.eName = :eName";
        return (User) this.createQuery(hqlString).setParameter("eName", eName).setMaxResults(1).uniqueResult();
    }

    public Integer dimission(String eName) {
        String hqlString = "UPDATE User u SET u.isDimission = :isDimission WHERE u.eName = :eName";
        return this.createQuery(hqlString).setParameter("eName", eName).setParameter("isDimission", Boolean.TRUE)
            .executeUpdate();
    }
}